
import { ajaxUseAuto, clearSpace } from '@/util.js'
import Cookies from 'js-cookie'  


// import { filter } from 'core-js/core/array'

//查询条件预设
const state = () => ({
    headers:{
        'Content-Type': 'multipart/form-data' 
    },
    uploadData:{
        token:null,
        applicationId:'y2jtobhqycwxb',
        moduleId: "b5pqetppe1nw3",
        fieldId: "ev0hxz7i0o6l7"      
    },
    uploadUrl:null,
    baseImgUrl:null,
    baseUrl:null,
    autoPlayVioce:localStorage.getItem('autoPlayVioce') == 'true'? true:false,//语音通知
    autoGetData:localStorage.getItem('autoGetData') == 'true'? true:false,//自动刷新数据表
})

// getters
const getters = {

}
// actions
const actions = {

   
    //轮询工单消息
    async searchMessage({state}) {
        let data = await ajaxUseAuto('search_message')
        let rentunValue = null
        if(data?.voiceContent?.path){
            rentunValue = state.baseImgUrl+data.voiceContent.path
        }
        return rentunValue
    },
    
  
    //提交查询计划列表条件
    async postFormP({ commit, state }, option) {

        option = state.form
      
        option.code = clearSpace(option.code)
        option.name = clearSpace(option.name)
     
        if (option.dateRange) {
            option.dateRangeStart = option.dateRange[0]
            option.dateRangeEnd = option.dateRange[1]
        }
        commit('pushLoading', true)
        // console.log(typeof ajaxUserAuto);
        let data = await ajaxUseAuto('idx_getPlanListAndCount', option)
     
        commit('pushListDataPlans', data)
        commit('pushLoading', false)

    },
   
}

// mutations
const mutations = {
    //设置
    //根据所处环境设置url
    setUrl(state,data){
        state.baseImgUrl = `${data}/web0/file/field/y2jtobhqycwxb/`;
        state.baseUrl =  process.env.NODE_ENV == "development"?"https://10.0.1.31:3000":`${data}/web0/website/y2jtobhqycwxb/sfydf2od4rvgl/`;
        state.uploadUrl = `${data}/web0/file/upload`
        console.log("设置token",Cookies.get('index_token'))
        let token = Cookies.get('index_token');
        if(process.env.NODE_ENV === 'development') {
            token = '94e56ebc65074ca1a6f7b90ab01c0134';
        }
        state.uploadData = {
            token,
            applicationId:'y2jtobhqycwxb',
            moduleId: "b5pqetppe1nw3",
            fieldId: "ev0hxz7i0o6l7"      
        }
    },
     //自动刷新
     setAutoGetData(state,data){
        localStorage.setItem('autoGetData',data)
        state.autoGetData = data
    }

}

export default {
    namespaced: true,
    state,
    getters,
    actions,
    mutations
}



